package com.hyper_yang._04_jvm.chap02;

public class ClassLoaderDemo1 {
    public static void main(String[] args) {

        //Class class2 = Car.class;
        //Class<?> aClass1 = Class.forName("com.mysql.jdbc.Driver");
        Car car = new Car();
        //Car car2 = new Car();
        Class<? extends Car> aClass = car.getClass(); //由对象得到类模板
        ClassLoader classLoader = aClass.getClassLoader(); //由类模板得到类加载器(快递员)
        //jdk.internal.loader.ClassLoaders$AppClassLoader@63947c6b
        System.out.println(classLoader); //Car的类加载器是AppClassLoader
    }
}

class Car {
    int id;
    String carName;
    static int age ;

    Car(){
        System.out.println("Car constructor - age = " + age);
    }

    static {
        age = 20;
        System.out.println("static block - age = " + age);
    }

    static {
        age = 22;
        System.out.println("static block - age = " + age);
    }

    {
        age = 40;
        System.out.println("instance block - age = " + age);
    }

    {
        age = 44;
        System.out.println("instance block - age = " + age);
    }
}